import {Component, ElementRef, ViewChild} from '@angular/core';
import {IonicPage, NavController, NavParams} from 'ionic-angular';
import {ApiProvider} from "../../providers/api/api";
import {CalendarComponentOptions} from "ion2-calendar";

import * as moment from 'moment';

/**
 * Generated class for the MySignListPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-my-sign-list',
  templateUrl: 'my-sign-list.html',
})
export class MySignListPage {

  userId;
  courseList;

  showSelect=false;
  courseName;
  classcourseId;

  constructor(public navCtrl: NavController, public navParams: NavParams,public http:ApiProvider) {
    moment.locale('zh-cn');
  }

  ionViewDidLoad() {
    this.userId=this.navParams.get("userId");
    this.getEnableCourseList();
  }

  /**
   * 构造班课下拉列表
   */
  getEnableCourseList()
  {
    this.http.post("/index/bannerIndex.do",{studentId:+this.userId,bannerType:1}).subscribe(item=>{
      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],"bottom");
      }
      else
      {
        this.courseList=item["indexCourseList"];

        for(let i=0;i<item["indexCourseList"].length;i++)
        {
          if(item["indexCourseList"][i]["isStartCourse"]!="2")
          {
            this.classcourseId=item["indexCourseList"][i]["classCourseId"];
            this.courseName=item["indexCourseList"][i]["className"]+"("+item["indexCourseList"][i]["teacherName"]+")";

            this.loadSignList(this.classcourseId);
          }
          break;
        }
      }
    })
  }

  /**
   *显示或隐藏班课下拉选择
   */
  showCourseSelect()
  {
    this.showSelect=!this.showSelect;
  }

  /**
   *下拉切换时，签到列表及显示头部修改
   */
  changeClassCourse(classcourse_id,courseName,teacherName)
  {
    this.showSelect=!this.showSelect;

    if(classcourse_id==this.classcourseId)
      return;


    this.classcourseId=classcourse_id;
    this.courseName=courseName+"("+teacherName+")";

    this.loadSignList(classcourse_id);
  }

  /**
   * 显示不同班课的签到列表
   * @param classcourse_id
   */
  loadSignList(classcourse_id)
  {
    this.http.post("/sign/signHistoryRecord.do",{studentId:this.userId,classCourseId:classcourse_id}).subscribe(item=>{

      if(item["Code"]=="11111111")
      {
        this.http.showToast(item["Message"],"bottom");
      }
      else
      {
        // console.log(typeof(item["History"])=="undefined");
        if(typeof(item["History"])=="undefined")
        {
          //没有数据
        }
        else
        {
          //有数据
          // console.log(item["History"]);
          this.dateMulti = item["History"];
        }
      }
    })
  }

  // calendar

  dateMulti: string[];
  type: 'string';
  optionsMulti: CalendarComponentOptions = {
    pickMode: 'multi',
    monthFormat: 'YYYY 年 MM 月 ',
    weekdays: ['日', '一', '二', '三', '四', '五', '六'],
    from: new Date(2000, 0, 1)
  };


}
